package com.geek.javase.wcy02;

import java.util.Scanner;

/**
 * @author wangchaoyang
 * @desc TODO
 * @date 2025/9/2
 */
public class IfDemo1 {
    public static void main(String[] args) {
        // ========== 需求1：简单计算器（接收两个数和运算符，执行运算） ==========
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入第一个数字：");
        double num1 = scanner.nextDouble();

        System.out.print("请输入第二个数字：");
        double num2 = scanner.nextDouble();

        System.out.print("请输入运算符号(+、-、*、/)：");
        String operator = scanner.next();

        double result = 0;
        if ("+".equals(operator)) {
            result = num1 + num2;
        } else if ("-".equals(operator)) {
            result = num1 - num2;
        } else if ("*".equals(operator)) {
            result = num1 * num2;
        } else if ("/".equals(operator)) {
            if (num2 != 0) { // 额外处理：除数不能为0
                result = num1 / num2;
            } else {
                System.out.println("错误：除数不能为0！");
                return;
            }
        } else {
            System.out.println("错误：不支持的运算符！");
            scanner.close();
            return;
        }
        System.out.println(num1 + operator + num2 + "=" + result);
    }
}
